//
//  SearchTabelFootView.m
//  YiTangZuoWenKe
//
//  Created by Work on 17/3/21.
//  Copyright © 2017年 wyp. All rights reserved.
//切换城市的历史访问View

#import "SearchTabelFootView.h"

@implementation SearchTabelFootView
-(instancetype)init{
    if (self = [super init]) {
        [self addView];
    }
    return self;
}
-(void)addView{
    [self addSubview:self.titleLabel];
    [self addSubview:self.cleanBtn];
    [self addSubview:self.BgView];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo (self);
        make.left.equalTo(self.mas_left).with.offset(12);
    }];
    [self.BgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo (self.titleLabel.mas_bottom);
        make.right.equalTo(self.mas_right);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo (self.mas_bottom);
    }];
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
-(UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"历史访问";
        _titleLabel.font = H13;
        _titleLabel.textColor =COLOR4;
        _titleLabel.numberOfLines = 0;
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}
-(UIView *)BgView{
    if (!_BgView) {
        _BgView = [[UIView alloc]init];
    }
    return _BgView;
}
-(void)creatView:(NSMutableArray *)array{
    CGFloat i = 0.0;
    CGFloat left = 12;
    CGFloat top = 12;
    for (NSString *str in array) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:str forState:UIControlStateNormal];
        [btn setTitleColor:RGBA(40,40,40, 1) forState:UIControlStateNormal];
        btn.titleLabel.font = H17;
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 4;
        btn.layer.borderWidth =0.5;
        btn.layer.borderColor = RGBA(152, 152, 152, 1).CGColor;
        [btn sizeToFit];
        if(left + i +btn.frame.size.width +10 > KSCREEWIDTH){
            top = 60;
            i =0.0;
            btn.frame = CGRectMake(left + i, top , 110, 36);
        }else{
            btn.frame = CGRectMake(left + i, top , 110 , 36);
        }
        [btn addTarget:self action:@selector(searchViewClick:) forControlEvents:UIControlEventTouchUpInside];
        i = CGRectGetMaxX(btn.frame);
        [self.BgView addSubview:btn];
    }
}
-(void)cleanView{
    for (id obj in self.BgView.subviews){
        if ([obj isKindOfClass:[UIButton class]]){
            UIButton* theButton = (UIButton*)obj;
            [theButton removeFromSuperview];
        }
    }
}
-(void)searchViewClick:(id)sender{
    UIButton*btn = (UIButton *)sender;
    if (self.delegate && [self.delegate respondsToSelector:@selector(searchViewClick:)]) {
        [self.delegate searchViewClick:btn.titleLabel.text];
    }
}


@end
